package com.space.rabbitmq.config;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;


/**
 * RabbitMq配置
 *
 * @author zhanglei
 */
@Configuration
public class RabbitMqConfig {

    /** 死信消息交换机的名字 1 */
    public static final String EXCHANGE_ONE_DEAD = "first-dead-exchange";
    /** 死信对列1 */
    public static final String QUEUE_NAME_DEAD1 = "first-dead-queue";
    /** 死信routing-key1 */
    public static final String ROUTINGKEY_DEAD1 = "first-queue_dead_key";
    /** 延迟对列1 */
    public static final String QUEUE_NAME_DELAY1 = "first-delay-queue";
    /** 延迟队列key1 */
    public static final String ROUTINGKEY_DELAY1 = "first-queue_delay_key";
    /** 延迟时间，单位毫秒 */
    public static final long DELAY_TIME = 10000;



    /** 对列1 */
    public static final String QUEUE_NAME1 = "first-queue";
    /** 对列2 */
    public static final String QUEUE_NAME2 = "second-queue";
    /** 对列3 */
    public static final String QUEUE_NAME3 = "third-queue";
    /** 对列4 */
    public static final String QUEUE_NAME4 = "fourth-queue";
    /** 对列5 */
    public static final String QUEUE_NAME5 = "fifth-queue";
    /** 对列6 */
    public static final String QUEUE_NAME6 = "sixth-queue";



    /** 连接工厂 */
    @Autowired
    private ConnectionFactory connectionFactory;
    /** 队列配置文件 */
    @Autowired
    private QueueConfig queueConfig;



    /**
     * queue listener  观察 监听模式
     * 当有消息到达时会通知监听在对应的队列上的监听对象
     *      待研究：SimpleMessageListenerContainer，目前此配置方法没有作用，待研究明白再参与使用
     * @return
     */
//    @Bean
//    public SimpleMessageListenerContainer simpleMessageListenerContainerOne() {
//        SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer(connectionFactory);
//        simpleMessageListenerContainer.addQueues(queueConfig.firstQueue());
//        simpleMessageListenerContainer.setExposeListenerChannel(true);
//        simpleMessageListenerContainer.setMaxConcurrentConsumers(5);
//        simpleMessageListenerContainer.setConcurrentConsumers(1);
//        //设置确认模式手工确认
//        simpleMessageListenerContainer.setAcknowledgeMode(AcknowledgeMode.MANUAL);
//        return simpleMessageListenerContainer;
//    }
}
